﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using RuleCode.Table;

namespace map.member
{
    public partial class pbbs : System.Web.UI.Page
    {
        cbarea area;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bind1();
                bind2();
            }
        }

        private void bind1()
        {
            cbuser us = cbuser.Find(" cbuserid = '" + AliApi.appUserId + "' ");
            HyperLink_openbbs.NavigateUrl = "http://" + us.RECID.ToString() + ".bbs.f980.com/";
            //HyperLink_openbbs.NavigateUrl = ResolveUrl("~/bbs.aspx") + "?userid=" + us.RECID.ToString();
        }
        /// <summary>
        /// 最新发帖等
        /// </summary>
        private void bind2()
        {
            cbuser u1 = cbuser.u();
            area = cbarea.Find(" cbuserid = '" + u1.cbuserid.ToString() + "'");
            this.Label_name.Text= area.cbtitle.ToString();

            if (area.enablepaihang.Value == RuleCode.Enum.NoYes.No)
            {
                return;
            }

            DataTable a1;
            string sql = "";
            sql = " select top 10 cblistid,cbtitle from vcblist where cbstatus = '有效' and cblisttype = '发帖' "
                + " and ( cbcatastatus = '" + area.cbareaid.ToString()
                + "' )";//or cbcatastatus = '全部'
            if (AliApi.appInstanceId != "")
            {
                sql += " and area = '" + AliApi.appInstanceId + "' ";
            }
            sql += " order by recid desc ";
            a1 = RuleCode.Common.SqlHelper.Instance.ExecuteQuery(sql).Tables[0];
            GridView_newnotes.DataSource = a1;
            GridView_newnotes.DataBind();
            sql = " select top 10 cblistid,cbtitle from vcblist where cbstatus = '有效' and cblisttype = '发帖' "
                + " and ( cbcatastatus = '" + area.cbareaid.ToString()
                + "' )";//or cbcatastatus = '全部'
            if (AliApi.appInstanceId != "")
            {
                sql += " and area = '" + AliApi.appInstanceId + "' ";
            }
            sql += " and jccreatedate <= '" + DateTime.Today.AddDays(1).ToShortDateString() + "' and jccreatedate >= '" + DateTime.Today.AddDays(-30).ToShortDateString() + "' "
                + " order by (chakanshu + huifushu*10) desc ";
            a1 = RuleCode.Common.SqlHelper.Instance.ExecuteQuery(sql).Tables[0];
            GridView_mth.DataSource = a1;
            GridView_mth.DataBind();

            sql = " SELECT  top 10   count(*) as shuliang,cbuserid,max(isnull(cbusernickname,'')) as cbusernickname,max(isnull(userrecid,'')) as userrecid FROM   vcblist where cbuserid != '' and  cbstatus = '有效' "
    + " and jccreatedate >= '" + DateTime.Today.ToShortDateString() + "'  "
                + " and ( cbcatastatus = '" + area.cbareaid.ToString()
                + "' )";//or cbcatastatus = '全部'
            if (AliApi.appInstanceId != "")
            {
                sql += " and area = '" + AliApi.appInstanceId + "' ";
            }
            sql += " group by cbuserid order by shuliang desc ";
            a1 = RuleCode.Common.SqlHelper.Instance.ExecuteQuery(sql).Tables[0];
            GridView_today.DataSource = a1;
            GridView_today.DataBind();

            sql = " SELECT  top 10   count(*) as shuliang,cbuserid,max(isnull(cbusernickname,'')) as cbusernickname,max(isnull(userrecid,'')) as userrecid FROM   vcblist where cbuserid != '' and  cbstatus = '有效' "
+ " and jccreatedate >= '" + DateTime.Today.Year.ToString() + "-01-01" + "'  "
                + " and ( cbcatastatus = '" + area.cbareaid.ToString()
                + "' )";//or cbcatastatus = '全部'
            if (AliApi.appInstanceId != "")
            {
                sql += " and area = '" + AliApi.appInstanceId + "' ";
            }
            sql += " group by cbuserid order by shuliang desc ";
            a1 = RuleCode.Common.SqlHelper.Instance.ExecuteQuery(sql).Tables[0];
            GridView_year.DataSource = a1;
            GridView_year.DataBind();
        }
    }
}
